home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3619 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Source utilities for endian conversion
  5. Date: 29 Jan 1996 18:23:41 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4ejvfdINN4tg@keats.ugrad.cs.ubc.ca>
  8. References: <rt9sph42r1m.fsf@topo.nist.gov>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <rt9sph42r1m.fsf@topo.nist.gov>,
  12. Paul J Sullivan <sullypj@topo.nist.gov> wrote:
  13. >I am trying to write a routine (c is not my first language) that will
  14. >allow me to read a binary data file on various platforms. I have
  15. >encountered the -endian problem and, thus, was wondering what routines
  16. >exist to convert between big- and little- formats. Is it possible to
  17. >do this without the conversion i.e. somehow specify a directive?? Is
  18. >it in a FAQ?
  19.  
  20. Try Sun XDR. I use it. It's not bad. It exists in freely distributed form.
  21.  
  22. XDR gives you tools to serialize basic data types into memory buffers or
  23. standard I/O streams, and to deserialize them.
  24.  
  25. You create an XDR stream like this:
  26.  
  27.     XDR encode;
  28.     char mybuffer[1024];
  29.     long a = 3;
  30.     char c = 'a';
  31.  
  32.     xdrmem_create(&encode, mybuffer, 1024, XDR_ENCODE);
  33.  
  34.     xdr_long(&encode, &a);
  35.     xdr_char(&encode, &c);
  36.  
  37.     printf("Encoded bytes: %d\n", xdr_getpos(&encode));
  38.  
  39. The ``rpcgen'' utility will automatically generate routines which recursively
  40. pack and unpack complex data structures from C-like structure definitions, and
  41. will also produce C headers declaring these structures.
  42.  
  43. >Appreciate the help.
  44. >
  45. >
  46. >-- 
  47. >Paul
  48. >
  49. > -----------------------------------------------------
  50. >| Dr Paul J. Sullivan            sullypj@enh.nist.gov |
  51. >| National Institute of Standards & Technology (NIST) |
  52. >| Tel: (301) 975 6386             Fax: (301) 869 0822 |
  53. >| http://www.coe.uncc.edu/~pjsulliv/                  |
  54. > -----------------------------------------------------
  55.  
  56.  
  57. -- 
  58.  
  59.